<?php

if( ! defined('DOCROOT') )
{
    require_once '/var/www/advancelab/chilik2/unittest/bootstrap.php';
}
      
class HttpResponseWriterTest extends WebTestCase
{
    function testingSimple()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_simpletest.php');
        
        $this->assertText( 'CF Body - Simple Test');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 21);
        
        /* $this->showHeaders(); */
    }
    
    function testingGenerator()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_generatortest.php');
        
        $this->assertText( 'CF Body - Generator Test');
        $this->assertHeader( 'X-Powered-By','cfController');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 24);
        
        /* $this->showHeaders(); */
    }
    
    function testingCookie()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_cookietest.php');
        
        $this->assertText( 'CF Body - Cookie Test');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 21);
        $this->assertHeader( 'Set-Cookie', 'simple=one');
        
        /* $this->showHeaders(); */
    }
    
    function testingCookies()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_cookiestest.php');
        
        $this->assertText( 'CF Body - Cookies Test');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date', date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 22);
        $this->assertHeader( 'Set-Cookie', 'simple=one');
        $this->assertHeader( 'Set-Cookie', 'complex=e%3Dmc%5E2; path=/test; domain=cf.no; secure; httponly');
        $this->assertHeader( 'Set-Cookie', 'speed=v%3D9.8%2A%28m%2Fs%5E2%29; httponly');
        $this->assertHeader( 'Set-Cookie', 'warp=G%3D%288%2Api%2Fc%5E4%29GT; secure');
        
        /* $this->showHeaders(); */
    }
    
    function testingDate()
    {
        /*
         * Note: We failed to pass this test because no configuration being set for $response->date properties
         */
         
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_datetest.php');
        
        $this->assertText( 'CF Body - Date Test');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date', date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 19);
        
        /* $this->showHeaders(); */
    }
    
    
    function testingCache()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_cachetest.php');
        
        $this->assertText( 'CF Body - Cache Test');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date', date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 20);
        $this->assertHeader( 'Vary', '*');
        $this->assertHeader( 'Cache-Control', 'no-store, no-cache, must-revalidate');
        $this->assertHeader( 'Pragma', 'no-cache');
        $this->assertHeader( 'Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
        
        /* $this->showHeaders(); */
    }
    
    function testingLanguage()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_languagetest.php');
        
        $this->assertText( 'CF Body - Language Test');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 23);
        $this->assertHeader( 'Content-Language', 'id-ID');
        
        /* $this->showHeaders(); */
    }
    
    function testingLanguage2()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_language2test.php');
        
        $this->assertText( 'CF Body - Language Test 2');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 25);
        $this->assertHeader( 'Content-Language', 'en-US');
        
        /* $this->showHeaders(); */
    }
    
    function testingContentTypeCharset1()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_contenttypecharset1test.php');
        
        $this->assertText( 'CF Body - Content Type Charset Test 1');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 37);
        $this->assertHeader( 'Content-Type', 'text/html+test');
        
        /* $this->showHeaders(); */
    }
    
    function testingContentTypeCharset2()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_contenttypecharset2test.php');
        
        $this->assertText( 'CF Body - Content Type Charset Test 2');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 37);
        $this->assertHeader( 'Content-Type', 'text/html+test; charset=latin1');
        
        /* $this->showHeaders(); */
    }
    
    function testingContentTypeCharset3()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_contenttypecharset3test.php');
        
        $this->assertText( 'CF Body - Content Type Charset Test 3');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 37);
        $this->assertHeader( 'Content-Type', 'text/html; charset=utf-8');
        
        /* $this->showHeaders(); */
    }
    
    function testingContentTypeDispositionSimple1()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_contentdisposition1test.php');
        
        $this->assertText( 'CF Body - Content Disposition Simple 1');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 38);
        $this->assertHeader( 'Content-Disposition', 'inline');
        
        /* $this->showHeaders(); */
    }
    
    function testingContentTypeDispositionSimple2()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_contentdisposition2test.php');
        
        $this->assertText( 'CF Body - Content Disposition Simple 2');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 38);
        $this->assertHeader( 'Content-Disposition', 'attachment; size=42');
        
        /* $this->showHeaders(); */
    }
    
    function testingContentTypeDispositionDate()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_contentdispositiondatetest.php');
        
        $this->assertText( 'CF Body - Content Disposition Date');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 34);
        $this->assertHeader( 'Content-Disposition', 'inline; creation-date="'.
                              date_create()->modify( '-1 day' )->format( DateTime::RFC2822 ).'"'.
                              '; modification-date="'.date_create()->modify( '-1 hour' )->format( DateTime::RFC2822 ).'"'.
                              '; read-date="'. date_create()->format( DateTime::RFC2822 ).'"'
                              );
        
        /* $this->showHeaders(); */
    }
    
    function testingContentTypeDispositionFileName()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_contentdispositionfiletest.php');
        
        $this->assertText( 'CF Body - Content Disposition Filename');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 38);
        $this->assertHeader( 'Content-Disposition', 'inline; filename=test.pdf');
        
        /* $this->showHeaders(); */
    }
    
    function testingContentTypeDispositionFileNameWithSpecial()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_contentdispositionfile2test.php');
        
        $this->assertText( 'CF Body - Content Disposition Filename 2 - With Special Character');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 65);
        $this->assertHeader( 'Content-Disposition', 'inline; filename="banan kake er <godt>.pdf"');
        
        /* $this->showHeaders(); */
    }
    
    function testingContentTypeDispositionFileNameWithSpecial2()
    {
        $this->get('http://localhost/advancelab/chilik2/unittest/response/dtr_contentdispositionfile3test.php');
        
        $this->assertText( 'CF Body - Content Disposition Filename 3 - With Special Character 2');
        $this->assertHeader( 'X-Powered-By','Chilik Framework Components');
        $this->assertHeader( 'Date',date_create("Asia/Jakarta")->format( 'D, d M Y H:i:s \G\M\T'  ));
        $this->assertHeader( 'Content-Length', 67);
        $this->assertHeader( 'Content-Disposition', 'inline; filename*=utf-8\'\'bl%C3%A5b%C3%A6r+kake+er+%3Cgodt%3E.pdf');
        
        $this->showHeaders();
    }
}

